package com.company.creational.singleton_pattern.singleton;

/**
 * @ClassName LazySingleton2
 * @Author tiezheng.han
 * @Date 2020/8/28 9:42
 **/
public class Singleton {

    static {
        System.out.println("load outer class...");
    }

    private Singleton(){}

    private static class HolderClass{
        static {
            System.out.println("load static inner class...");
        }
        private static Singleton instance = new Singleton();
    }

    public static Singleton getInstance(){
      return HolderClass.instance;
    }

    public static void main(String[] args) {
        Singleton s1,s2;
        s1 = Singleton.getInstance();
        s2 = Singleton.getInstance();
        System.out.println(s1 == s2);
    }

}
